package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.ProjectPlan;
import com.ruoyi.system.service.ProjectPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 项目转化（计划）(project_plan)表控制层
 *
 * @author xxxxx
 */
@RestController
@RequestMapping("/system/plan")
public class ProjectPlanController extends BaseController
{
    @Autowired
    private ProjectPlanService projectPlanService;

    /**
     * 查询项目转化（计划）列表
     */
    @PreAuthorize("@ss.hasPermi('system:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProjectPlan projectPlan)
    {
        startPage();
        List<ProjectPlan> list = projectPlanService.selectProjectPlanList(projectPlan);
        return getDataTable(list);
    }

    /**
     * 导出项目转化（计划）列表
     */
    @PreAuthorize("@ss.hasPermi('system:plan:export')")
    @Log(title = "项目转化（计划）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectPlan projectPlan)
    {
        List<ProjectPlan> list = projectPlanService.selectProjectPlanList(projectPlan);
        ExcelUtil<ProjectPlan> util = new ExcelUtil<ProjectPlan>(ProjectPlan.class);
        util.exportExcel(response, list, "项目转化（计划）数据");
    }

    /**
     * 获取项目转化（计划）详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:plan:query')")
    @GetMapping(value = "/{planId}")
    public AjaxResult getInfo(@PathVariable("planId") Long planId)
    {
        return success(projectPlanService.selectProjectPlanByPlanId(planId));
    }

    /**
     * 新增项目转化（计划）
     */
    @PreAuthorize("@ss.hasPermi('system:plan:add')")
    @Log(title = "项目转化（计划）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectPlan projectPlan)
    {
        return toAjax(projectPlanService.updateProjectPlan(projectPlan));
    }

    /**
     * 修改项目转化（计划）
     */
    @PreAuthorize("@ss.hasPermi('system:plan:edit')")
    @Log(title = "项目转化（计划）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectPlan projectPlan)
    {
        return toAjax(projectPlanService.updateProjectPlan(projectPlan));
    }

    /**
     * 删除项目转化（计划）
     */
    @PreAuthorize("@ss.hasPermi('system:plan:remove')")
    @Log(title = "项目转化（计划）", businessType = BusinessType.DELETE)
    @DeleteMapping("/{planIds}")
    public AjaxResult remove(@PathVariable Long[] planIds)
    {
        return toAjax(projectPlanService.deleteProjectPlanByPlanIds(planIds));
    }
}


